package com.example.smartg;

import android.app.Application;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

import static com.zkteco.android.biometric.core.utils.ToolUtils.getApplicationContext;


public class HandlerUtils implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        String token = SpUtils.getString(getApplicationContext(), "token","");
        //SpUtils是SharedPreferences的工具类，自行实现
        if (token.equals("")) {
            Request originalRequest = chain.request();
            return chain.proceed(originalRequest);
        } else {
            Request originalRequest = chain.request();
            Request updateRequest = originalRequest.newBuilder().header("Authorization", token).build();
            return chain.proceed(updateRequest);
        }
    }
}
